abe622
@@ -2686,16 +2686,31 @@
public static boolean moveFile(HiveConf conf, Path srcf, Path destf,
             if (srcs.length == 0) {
               success = true; // Nothing to move.
             }
+
+            /* Move files one by one because source is a subdirectory of destination */
             for (FileStatus status : srcs) {
-              success = FileUtils.copy(srcf.getFileSystem(conf), status.getPath(), destf.getFileSystem(conf), destf,
-                  true,     // delete source
-                  replace,  // overwrite destination
-                  conf);
+              Path destFile;
 
-              if (!success) {
+              /* Append the source filename to the destination directory */
+              if (destFs.isDirectory(destf)) {
+                destFile = new Path(destf, status.getPath().getName());
+              } else {
+                destFile = destf;
+              }
+
+              // Destination should be replaced, so we delete it first
+              if (destFs.exists(destFile)) {
+                if (!destFs.delete(destFile, true)) {
+                  throw new HiveException(String.format("File to replace could not be deleted: %s", destFile));
+                }
+              }
+
+              if (!(destFs.rename(status.getPath(), destFile))) {
                 throw new HiveException("Unable to move source " + status.getPath() + " to destination " + destf);
               }
             }
+
+            success = true;
           } else {
             success = destFs.rename(srcf, destf);
           }
